package com.yanqu.road.server.cmd.activity.wealthscroll;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WealthScrollProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.WealthScrollModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.List;

@Cmd(code = GameProtocol.S_WEALTH_SCROLL_GET_REWARD,desc = "新财神密卷获取奖励")
public class WealthScrollGetRewardCmd extends AbstractCommand {

    private int activityId;

    private List<Integer> taskIds;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WealthScrollProto.WealthScrollGetRewardReq req = WealthScrollProto.WealthScrollGetRewardReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        taskIds = req.getTaskIdList();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WealthScrollModule.class).getReward(activityId, taskIds);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            WealthScrollProto.WealthScrollGetRewardResp.Builder builder = WealthScrollProto.WealthScrollGetRewardResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_WEALTH_SCROLL_GET_REWARD, builder);
        }
    }
}
